#ifndef __WIZ_CALL_ONCE_HPP__SHANHAOBO_19800429__
#define __WIZ_CALL_ONCE_HPP__SHANHAOBO_19800429__

#include "./WizInterlocked.hpp"
#include "../Base/WizBase.hpp"

namespace Wiz
{
    namespace CallOnce
    {
        namespace Flag
        {
            #if (WIZ_CFG_PLATFORM == WIZ_CFG_PLATFORM_WINDOWS)
                WIZ_DECLARE(LONG);
                static const LONG Init      = 0;
                static const LONG Completed = 0xc15730e2;
            #else
            #endif /*WIZ_CFG_PLATFORM == WIZ_CFG_PLATFORM_WINDOWS*/
        }; /// end of namespace Flag

        template<typename FunctionT>
        ::Wiz::Void::Type Do(::Wiz::CallOnce::Flag::InOut Flg, FunctionT Func)
        {
            if (::Wiz::Interlocked::CompareExchange(&Flg, ::Wiz::CallOnce::Flag::Init, ::Wiz::CallOnce::Flag::Completed) != ::Wiz::CallOnce::Flag::Completed)
            {
                Func();
            }
        }
    } /// end of namespace CallOnce
} /// end of namespace Wiz

#endif /*__WIZ_CALL_ONCE_HPP__SHANHAOBO_19800429__*/
